Vue.component('Update', {
  template: `
		<el-dialog title="修改" width="600px" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width=" ismobile()?'90px':'16%'">
				<el-row >
					<el-col :span="24">
						<el-form-item label="名称" prop="name">
							<el-input  v-model="form.name" autoComplete="off" clearable  placeholder="请输入 名称"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row >
					<el-col :span="24">
						<el-form-item label="排序" prop="sort">
							<el-input-number controls-position="right" style="width:200px;" autoComplete="off" v-model="form.sort" clearable :min="0" placeholder="排序"/>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">确 定</span>
					<span v-else>提 交 中...</span>
				</el-button>
				<el-button :size="size" @click="closeForm">取 消</el-button>
				<Icon :iconshow.sync="iconDialogStatus" :icon.sync="form.icon" size="small"></Icon>
			</div>
		</el-dialog>
	`
  ,
  components: {
    'treeselect': VueTreeselect.Treeselect,
  },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: 'small'
    },
    info: {
      type: Object,
    },
  },
  data() {
    return {
      form: {
        title: '',
        type: 1,
        path: '',
        status: 1,
        icon: '',
      },
      pids: [],
      loading: false,
      iconDialogStatus: false,
      rules: {
        title: [
          { required: true, message: '节点名称不能为空', trigger: 'blur' },
        ],
      }
    }
  },
  watch: {
    show(val) {
      if (val) {
        // axios.post('/admin/node/getFieldList').then(res => {
        //   if (res.data.status == 200) {
        //     this.pids = res.data.data
        //   }
        // })
      }
    }
  },
  methods: {
    open() {
      this.form = this.info
      if (this.info.pid == '0') {
        this.$delete(this.info, 'pid')
      }
    },
    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          axios.post('/admin/goods/cateUpdate', this.form).then(res => {
            if (res.data.status == 200) {
              this.$message({ message: res.data.msg, type: 'success' })
              this.$emit('refesh_list')
              this.closeForm()
            } else {
              this.loading = false
              this.$message.error(res.data.msg)
            }
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.val,
        label: node.key,
        children: node.children
      }
    },
    closeForm() {
      this.$emit('update:show', false)
      this.loading = false
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
    },
  }
})
